<?php
include_once( 'Include/init.php' );

$urls = isset($_GET['urls']) ? trim($_GET['urls'], '/') : 'Index/Show';

if (isset($_GET['urls'])) unset($_GET['urls']);

$params = explode('/', $urls);
//处理get
$count = count($params);
if ($count<3 && $count>0){
	if(ucfirst($params[0])!='Admin' && ucfirst($params[0])!='Page'){
		array_unshift($params, 'Page');
	}
}
$appName = ucfirst(isset($params[0]) ? $params[0] : 'Page');
$ctrName = ucfirst(isset($params[1]) ? $params[1] : 'Index');
$mtdName = isset($params[2]) ? $params[2] : 'Show';
if ($count>2){
	for ($i=3; $i<$count; $i=$i+2){
		$_GET[$params[$i]] = isset($params[$i+1]) ? $params[$i+1] : '';
	}
}
define('APP_NAME', $appName);
//调用接口
$filename = ROOT_DIR . "Controllers/{$appName}/{$ctrName}.php";

if (!file_exists($filename)){
	exit('Page Not Found');
}
require_once $filename;

$ctrIst = new $ctrName();

$ctrIst->$mtdName();

//自动加载文件
function __autoload($classname)
{
	$findPath = array(
		ROOT_DIR . 'Libraries/' . $classname . '.php',
		ROOT_DIR . 'Controllers/' . APP_NAME . '/' . $classname . '.php',
		ROOT_DIR . 'Modules/' . $classname . '.php',
	);
	
	foreach ($findPath as $filename){
		if (file_exists($filename)){
			require_once $filename;
			return true;
		}
	}
	return false;
}
